<?php

namespace app\common\model\base;

use app\common\model\BaseModel;
use helper\Files;

class AttachmentModel extends BaseModel
{

  protected $table = 'attachment';

  /**
   * 格式化列表
   * @param $list
   * @return mixed
   */
  public function _formatList($list)
  {
    $groupIds      = array_unique(array_column($list,'group_id'));
    $groupNames    = AttachmentGroupModel::where('id', 'in', $groupIds)->column('group_name', 'id');
    $groupNames[0] = '未分组';
    foreach ($list as $k => $v) {
      $list[$k]['file_size']   = Files::byteFormat($v['file_size']);
      $list[$k]['group_name']  = $groupNames[$v['group_id']] ?? '';
    }
    return $list;
  }

  public function add($data){
      return self::create($data);
  }

}